<?php

namespace app\man\controller;

use think\Controller;
use think\Db;
use think\Paginator;
use think\Cache;
use think\Request;
class Suz extends Common
{
	public function dlist(){
		 
		$domains = Db::name("suz")->paginate();

		$this->assign('list',$domains);

		return $this->fetch('list');
	}

	public function add(){

		return $this->fetch('add');
	}
	public function doadd()
	{

		$domains = input('domains');
		$com_appid = input('com_appid');
		$share = input('share');
		$lists = explode("\n",$domains);
		foreach($lists as $k=>$val){
			$data[$k]['domain']=trim($val);
			$data[$k]['status']=1;
			$data[$k]['province']=$com_appid;
			$data[$k]['share']=$share;
		}
		$result = Db::name("suz")->insertAll($data);
		if($result){
			$this->success('添加成功', url('man/suz/add'), 3);
		}else{
			$this->success('添加失败');
		}

	}

	public function change(){
		$aid=input('aid');
		$status=input('status');
 
 
		if($status==2){
			$options = [
	            // 缓存类型为File
	            'type'  =>  'Redis', 
	            // 缓存有效期为永久有效
	            //缓存前缀
	            'prefix'=>  'think',
	             // 指定缓存目录
	            'host'  =>  '127.0.0.1',

	            'port'  => '6379'
	        ];
	        
			$res = Db::name("suz")->where('id',$aid)->update(['status'=>$status,'start_time'=>date("Y-m-d H:i:s")]);
			Cache::connect($options);
			cache::rm("component_access_tokenstst");
			cache::rm("osman_suz_arrive3_thirdst");
			cache::rm("osman_token_news_suzkb3ccst");
			cache::rm("osman_ticket_news_suzkb3ccst");
		}else{
			$options = [
	            // 缓存类型为File
	            'type'  =>  'Redis', 
	            // 缓存有效期为永久有效
	            //缓存前缀
	            'prefix'=>  'think',
	             // 指定缓存目录
	            'host'  =>  '127.0.0.1',

	            'port'  => '6379'
	        ];
	        
			$res = Db::name("suz")->where('id',$aid)->update(['status'=>$status]);
			Cache::connect($options);
			cache::rm("component_access_tokenstst");
			cache::rm("osman_suz_arrive3_thirdst");
			cache::rm("osman_token_news_suzkb3ccst");
			cache::rm("osman_ticket_news_suzkb3ccst");
		}

		if($status==3){
			$res = Db::name("suz")->where('id',$aid)->update(['status'=>$status,'end_time'=>date("Y-m-d H:i:s")]);
		}else{
			$res = Db::name("suz")->where('id',$aid)->update(['status'=>$status]);
		}
		if($status ==1){
			$res = Db::name("suz")->where('id',$aid)->update(['status'=>$status]);
		}

		if($res===false){
			return false;
		}else{
 
			
		return true;
		}
	}
	public function cblur(){
		$nid = input('aid');

		$bek = input('province');

		$res = Db::name('suz')->where('id',$nid)->update(['share'=>$bek]);

		if($res){
			echo true;
		}else{
			echo false;
		}
	}
	public function delete(){
		$id = input('id');

		$res = Db::name('suz')->where('id',$id)->delete();

		if($res){
			$this->success('删除成功');
		}else{
			$this->success('删除失败');
		}
	}
}